package com.quanxiaoha.xiaohashu.user.biz.controller;


import com.quanxiaoha.framework.biz.context.holder.LoginUserContextHolder;
import com.quanxiaoha.framework.biz.operationlog.aspect.ApiOperationLog;
import com.quanxiaoha.framework.common.response.Response;
import com.quanxiaoha.xiaohashu.user.biz.model.vo.UpdateUserInfoReqVO;
import com.quanxiaoha.xiaohashu.user.biz.service.UserService;
import com.quanxiaoha.xiaohashu.user.dto.req.FindUserByIdReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.req.FindUserByPhoneReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.req.RegisterUserReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.req.UpdateUserPasswordReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.resp.FindUserByIdRspDTO;
import com.quanxiaoha.xiaohashu.user.dto.resp.FindUserByPhoneRspDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: jingyan_liu
 * @CreateTime: 2025-07-21
 * @Description:
 * @Version: 1.0
 */


@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {
	
	@Resource
	private UserService userService;
	
	@PostMapping(value = "/update", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	public Response<?> updateUserInfo(@Validated @RequestBody UpdateUserInfoReqVO updateUserInfoReqVO) {
		log.info("当前用户 ID: {}", LoginUserContextHolder.getUserId());
		Response<?> response = userService.updateUserInfo(updateUserInfoReqVO);
		return Response.success();
	}
	
	@PostMapping("/register")
	@ApiOperationLog(description = "用户注册")
	public Response<Long> register(@Validated @RequestBody RegisterUserReqDTO registerUserReqDTO) {
		return userService.register(registerUserReqDTO);
	}
	
	@PostMapping("/findByPhone")
	@ApiOperationLog(description = "手机号查询用户信息")
	public Response<FindUserByPhoneRspDTO> findByPhone(@Validated @RequestBody FindUserByPhoneReqDTO findUserByPhoneReqDTO) {
		return userService.findByPhone(findUserByPhoneReqDTO);
	}
	
	@PostMapping("/password/update")
	@ApiOperationLog(description = "更新密码")
	Response<?> updatePassword(@Validated @RequestBody UpdateUserPasswordReqDTO updateUserPasswordReqDTO) {
		return userService.updatePassword(updateUserPasswordReqDTO);
	}
	
	@PostMapping("/findById")
	@ApiOperationLog(description = "查询用户信息")
	public Response<FindUserByIdRspDTO> findById(@Validated @RequestBody FindUserByIdReqDTO findUserByIdReqDTO) {
		return userService.findById(findUserByIdReqDTO);
		
	}
}
